package com.jluzh.low_level.com.jluzh.service;

import com.jluzh.low_level.com.jluzh.model.Book;
import com.jluzh.low_level.com.jluzh.model.BookView;
import com.jluzh.low_level.com.jluzh.repository.BookRepository;
import com.jluzh.low_level.com.jluzh.repository.BookViewRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author EvanHuang
 * @date 1/23/2019 11:12 AM
 * @since
 */
@Service
public class BookService {
    @Autowired
    private BookRepository bookRepository;

    @Autowired
    private BookViewRepository bookViewRepository;

    public BookView findBook(Long id) {
//        return bookViewRepository.findViewById(id);
        return bookViewRepository.findById(id).orElse(null);
    }

    public void createBook() {
        Book book = new Book();
        book.setAuthor("evan");
        book.setDescription("hello");
        book.setTitle("test");
        bookRepository.save(book);
    }
}
